new Vue({
  el: "#app",
  data() {
    return {
      gs: [],
      form: {
        Data: "reptile_config", //状态
        page: 1, //页数
        limit: 10, //每页数据条数
      },
      tableData: [], //表格数据
      total: 1,
      loading: false,
    };
  },
  mounted() {
    this.getList(this.form);
  },
  methods: {
    handleDelete(index, row) {
      console.log(index, row);
      const _this = this;
      $.ajax({
        // url: "https://service.kdddy.cn/donghuiForRedis/delete",
        url: "http://192.168.10.92:8086/delete",
        type: "get",
        data: row,
        success: function (Result) {
          console.log(Result);
          if (Result.Status === "Success") {
            _this.tableData.splice(index, 1);
          } else {
            _this.$message.error("提交失败，请稍后再试");
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest); //config/config.js 响应预检
        },
        dataType: "json",
      });
    },
    onSerach() {
      //查询方法
      this.form.page = 1;
      this.getList(this.form);
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form);
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form);
    },
    getList(data) {
      //换页方法
      let _this = this;
      $.ajax({
        headers: {
          AccessToken: $.cookie("token"), //会将数据转换为query string
        },
        type: "get",
        // url: "http://192.168.10.92:8086/selectData",
        url: "https://service.kdddy.cn/donghuiForRedis/selectData",
        complete: function (XMLHttpRequest) {
          _this.loading = false;
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href =
              absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        success: function (Result) {
          const parsedArray = Result.Data.map((jsonStr) => JSON.parse(jsonStr));
          console.log(parsedArray);
          parsedArray.forEach((item) => {
            const newsItem = item.News[0];
            // const urlObject = {
            //   Reptile_URL: newsItem.URL,
            // };
            // _this.gs.push(newsItem);
            // console.log("URL:", newsItem.URL);
            // 将对象添加到数组中
            // _this.tableData.push(urlObject);
            _this.tableData.push(newsItem);
            // this.tableData.push(newsItem.URL);
            console.log("News Type:", newsItem.News_Type);
            console.log("---");
          });
          console.log(_this.gs);
          console.log(_this.tableData);

          _this.total = Number(Result.limit);
        },
        dataType: "json",
      });
    },
    Add() {
      window.location.href = "./Add.html";
    },
    handleSelectionChange() {
      //多选
    },
  },
});
